if(fastman) {
  // 通过ready接口建立桥接程序
  fastman.ready(function(){
    console.log("[ready]: ok");

    if(fastman.isFromApp()) {
      console.log("sd视频见证[result_video]");
      fastman.subscribeNotify("result_video", function(data) {
        var dataJson = JSON.stringify(data);
        console.log('sd视频见证[result_video] <- ' + dataJson);
        weui.alert(dataJson, { title: "result_video callback" });
      });
    }
    
    weui.topTips("已成功建立桥接通道", {
      duration: 1500,
      className: "toptips-normal"
    });

    // 注册页面出现时的触发事件
    fastman.onViewWillAppear(function () {
      weui.topTips("onViewWillAppear被系统自动回调了", {
        duration: 1500,
        className: "toptips-normal"
      });
    });
  });

  // 查询鉴权信息
  $("#OAuth").on("click", function(){
    fastman.oauth({
      success: function(res){
        weui.alert(JSON.stringify(res), { title: "OAuth success" });
      },
      fail: function(err){
        weui.alert(JSON.stringify(err), { title: "OAuth fail" });
      }
    });
  });

  // 判断当前容器是否是APP
  $("#isFromApp").on("click", function(){
    weui.alert(fastman.isFromApp(), { title: "isFromApp success" });
  });

  // 查询App版本
  $("#getVersion").on("click", function(){
    weui.alert(fastman.getVersion(), { title: "getVersion success" });
  });

  // 判断其它容器
  $("#isFromIOS").on("click", function(){
    weui.alert(fastman.isFromIOS(), { title: "isFromIOS success" });
  });
  $("#isFromAndroid").on("click", function(){
    weui.alert(fastman.isFromAndroid(), { title: "isFromAndroid success" });
  });
  $("#isFromHarmony").on("click", function(){
    weui.alert(fastman.isFromHarmony(), { title: "isFromHarmony success" });
  });
  $("#isFromWeiXin").on("click", function(){
    weui.alert(fastman.isFromWeiXin(), { title: "isFromWeiXin success" });
  });

  // 查询窗口信息
  $("#getWindowInfo").on("click", function(){
    if (fastman.onGetWindowInfo) {
      fastman.onGetWindowInfo({
        success: function(response) {
          weui.alert(JSON.stringify(response), { title: "onGetWindowInfo success" });
        }
      });
    }
  });

  // 查询设备信息
  $("#getDeviceInfo").on("click", function(){
    if (fastman.onGetDeviceInfo) {
      fastman.onGetDeviceInfo({
        success: function(response) {
          weui.alert(JSON.stringify(response), { title: "onGetDeviceInfo success" });
        }
      });
    }
  });

  // 登录接口
  $("#onLogin").on("click", function(){
    var isCheckLogin = $("input[name='isCheckLogin']:checked").val();
    fastman.onLogin({
      isCheckLogin,
      success: function (res) {
        weui.alert(JSON.stringify(res), { title: "onLogin success" });
      },
      fail: function (err) {
        weui.alert(JSON.stringify(err), { title: "onLogin fail" });
      }
    });
  });

  // 登录增强
  $("#onLoginEnhance").on("click", function(){
    var fundAccount = $("#fundAccount").val();
    var fundtype = [];
    if ($("#a11").prop("checked")) {
      fundtype.push("3");
    }
    if ($("#a12").prop("checked")) {
      fundtype.push("6");
    }
    if ($("#a13").prop("checked")) {
      fundtype.push("18");
    }
    if ($("#a14").prop("checked")) {
      fundtype.push("810");
    }
    if ($("#a15").prop("checked")) {
      fundtype.push("820");
    }
    fastman.onLoginEnhance({
      fundAccount: fundAccount,
      fundtype: fundtype.join(","),
      success: function (res) {
        weui.alert(JSON.stringify(res), { title: "onLoginEnhance success" });
      },
      fail: function (err) {
        weui.alert(JSON.stringify(err), { title: "onLoginEnhance fail" });
      }
    });
  });
  
  // 导航头
  $("#onNavigateBar").on("click", function(){
    var title = $("#title").val();
    var rightButtonTitle = $("#rightButtonTitle").val();
    var rightButtonIcon = $("#rightButtonIcon").val();
    var isShowBackButton = $("input[name='isShowBackButton']:checked").val();
    if(isShowBackButton == "true") {
      isShowBackButton = true;
    } else {
      isShowBackButton = false;
    }
    var onRightButtonPress = () => {
      weui.alert("右上角按钮被点击", { title: "onRightButtonPress 回调处理" });
    }
    var params = {
      title: title,
      rightButtonTitle: rightButtonTitle,
      rightButtonIcon: rightButtonIcon,
      onRightButtonPress: onRightButtonPress,
      isShowBackButton: isShowBackButton
    };
    fastman.onNavigateBar(params);
  });

  // 跳转H5页面
  $("#onNavigateTo").on("click", function(){
    var title = $("#title2").val();
    var uri = $("#uri").val();
    var webviewVer = $("input[name='webviewVer']:checked").val();
    // 是否全屏模式，优先级高于hideNavigationBar和showDefaultHide设置（false-正常模式；true-全屏模式）
    var isFullScreen = $("input[name='isFullScreen']:checked").val();
    // 状态栏的文字颜色（仅在全屏模式下生效），默认为true（true-白色；false-黑色）
    var isStatusBarLight = $("input[name='isStatusBarLight']:checked").val();
    var hideNavigationBar = $("input[name='hideNavigationBar']:checked").val();
    var showDefaultHide = $("input[name='showDefaultHide']:checked").val();
    var params = {
      title: title,
      uri: uri,
      hideNavigationBar: hideNavigationBar,
      showDefaultHide: showDefaultHide,
      isFullScreen: isFullScreen == "0" ? false : true,
      isStatusBarLight: isStatusBarLight == "0" ? true : false,
      ver: webviewVer
    };
    console.log("[onNavigateTo params]: " + JSON.stringify(params));
    window.localStorage['App_URI_20220504'] = params.uri;
    fastman.onNavigateTo(params);
  });

  // 跳转原生页面
  $("#onNavigateNativeTo").on("click", function(){
    var url = $("#url").val();
    var params = {
      url: url
    };
    console.log("[onNavigateNativeTo params]: " + JSON.stringify(params));
    window.localStorage['App_DynamicLink_20230627'] = params.url;
    fastman.onNavigateNativeTo(params);
  });

  // 后退上一页面
  $("#onNavigateBack").on("click", function(){
    fastman.onNavigateBack();
  });

  // 身份证识别（OCR）接口
  $("#onIdCardOCR").on("click", function(){
    // var loading = weui.loading("loading");
    var mode = $("input[name='mode']:checked").val();
    var idcardImage = $("#idcardImage");
    fastman.onIdCardOCR({
      mode: mode,
      success: function (res) {
        if(res.frontData) {
          idcardImage.attr("src", "data:image/jpg;base64," + res.frontData);
          // 防刷屏
          res.frontData = "太长这里不做输出，请查看界面效果";
        }
        else if(res.backData) {
          idcardImage.attr("src", "data:image/jpg;base64," + res.backData);
          res.backData = "太长这里不做输出，请查看界面效果";
        }
        // loading.hide();
        weui.alert(JSON.stringify(res), { title: "onIdCardOCR success" });
      },
      fail: function (err) {
        // loading.hide();
        weui.alert(JSON.stringify(err), { title: "onIdCardOCR fail" });
      }
    });
  });

  // 身份证识别（OCR）接口
  $("#onFaceRecognition").on("click", function(){
    var modes = [];
    if ($("#q11").prop("checked")) {
      modes.push("0");
    }
    if ($("#q12").prop("checked")) {
      modes.push("1");
    }
    if ($("#q13").prop("checked")) {
      modes.push("2");
    }
    if ($("#q14").prop("checked")) {
      modes.push("3");
    }
    var faceImage = $("#faceImage");
    fastman.onFaceRecognition({
      mode: modes.join(","),
      success: function (res) {
        if(res.blinkImage) {
          faceImage.attr("src", "data:image/jpg;base64," + res.blinkImage);
        }
      },
      fail: function (err) {
        weui.alert(JSON.stringify(err), { title: "onFaceRecognition fail" });
      }
    });
  });

  // 社交分享
  $("#onShare").on("click", function(){
    var channel = $("input[name='channel']:checked").val();
    var title = $("#title3").val();
    var description = $("#description").val();
    var thumbImageUrl = $("#thumbImageUrl").val();
    var link = $("#link").val();
    var params = {
      channel: channel,
      title: title,
      description: description,
      thumbImageUrl: thumbImageUrl,
      link: link
    };
    console.log("[onShare params]: " + JSON.stringify(params));
    fastman.onShare(params);
  });

  // 社交分享
  $("#onImageShare").on("click", function(){
    var channel = $("input[name='onImageShare_channel']:checked").val();
    var imageDataURL = $("#onImageShare_imageDataURL").val();
    var params = {
      channel: channel,
      imageDataURL: imageDataURL
    };
    console.log("[onImageShare params]: " + JSON.stringify(params));
    fastman.onImageShare(params);
  });

  // 微信支付
  $("#onWxPay").on("click", function(){
    var wxPay_appId = $("#wxPay_appId").val();
    var wxPay_partnerId = $("#wxPay_partnerId").val();
    var wxPay_prePayId = $("#wxPay_prePayId").val();
    var wxPay_noncestr = $("#wxPay_noncestr").val();
    var wxPay_timestamp = $("#wxPay_timestamp").val();
    var wxPay_sign = $("#wxPay_sign").val();
    var params = {
      appId: wxPay_appId,
      partnerId: wxPay_partnerId,
      prePayId: wxPay_prePayId,
      noncestr: wxPay_noncestr,
      timestamp: wxPay_timestamp,
      sign: wxPay_sign
    };
    params.success = function(res) {
      weui.alert(JSON.stringify(res));
    }
    params.fail = function(err) {
      weui.alert(JSON.stringify(err), { title: "onWxPay fail" });
    }
    console.log("[onWxPay params]: " + JSON.stringify(params));
    fastman.onWxPay(params);
  });

  // 支付宝APP支付
  $("#onAliPay").on("click", function(){
    var aliPay_appPayRequest = $("#aliPay_appPayRequest").val();
    var params = {
      appPayRequest: aliPay_appPayRequest,
    };
    // 支付宝APP支付无回调事件，仅支付宝小程序提供回调事件
    // params.success = function(res) {
    //   alert(JSON.stringify(res));
    // }
    // params.fail = function(err) {
    //   weui.alert(JSON.stringify(err), { title: "onReq fail" });
    // }
    console.log("[onAliPay params]: " + JSON.stringify(params));
    fastman.onAliPay(params);
  });

  // App内接口调用
  $("#onReq").on("click", function(){
    var funcNo = $("#funcNo").val();
    var paramJsonStr = $("#paramJsonStr").val();
    var params = {};
    try {
      params = JSON.parse(paramJsonStr);
    } catch(err) {
      weui.alert("JSON格式错误，请参考示例的格式来传递", { title: "onReq error" });
    }
    params.success = function(res) {
      alert(JSON.stringify(res));
    }
    params.fail = function(err) {
      weui.alert(JSON.stringify(err), { title: "onReq fail" });
    }
    fastman.onReq(funcNo, params);
  });

  // 查询指定市场类型下最近一次登录的资金账号
  $("#onQueryLatestLoginAccount").on("click", function(){
    var bizSysId = [];
    if ($("#b11").prop("checked")) {
      bizSysId.push("3");
    }
    if ($("#b12").prop("checked")) {
      bizSysId.push("6");
    }
    if ($("#b13").prop("checked")) {
      bizSysId.push("18");
    }
    if ($("#b14").prop("checked")) {
      bizSysId.push("810");
    }
    fastman.onQueryLatestLoginAccount({
      bizSysId: bizSysId,
      success: function (res) {
        weui.alert(JSON.stringify(res), { title: "onQueryLatestLoginAccount success" });
      },
      fail: function (err) {
        weui.alert(JSON.stringify(err), { title: "onQueryLatestLoginAccount fail" });
      }
    });
  });

  // 检查App通知权限开启状态
  $("#onCheckAppNotification").on("click", function(){
    fastman.onCheckAppNotification({
      success: function (res) {
        // 未开启
        if(res.status == "0") {
          weui.confirm("未开启", {
            title: "onCheckAppNotification success",
            buttons: [{
                label: "取消",
                type: "default"
            }, {
                label: "去开启",
                type: "primary",
                onClick: function(){
                  fastman.onGoToCheckAppNotification();
                }
            }]
          });
        }
        // 已开启
        else {
          weui.alert("已开启", { title: "onCheckAppNotification success" });
        }
      },
      fail: function (err) {
        weui.alert(JSON.stringify(err), { title: "onCheckAppNotification fail" });
      }
    });
  });

  // 跳转至App通知权限系统页
  $("#onGoToCheckAppNotification").on("click", function(){
    console.log("跳转至App通知权限系统页");
    fastman.onGoToCheckAppNotification();
  });

  // 获取自选股列表
  $("#onGetOptionalStocks").on("click", function(){
    console.log("获取自选股列表");
    fastman.onGetOptionalStocks({
      success: function(res) {
        if(res.list && res.list.length > 0 && !__POWERED_BY_OEMAPP__) {
          res.list.forEach(e =>  {
            console.warn(`dfyj://dl/stockdetailpage?code_53=${e.code}&type_53=${e.type}`)
          });
        }
        weui.alert(JSON.stringify(res.list), { title: "自选股列表" });
      },
      fail: function (err) {
        console.error(err.info)
      }
    });
  });

  // 唤起App
  $("#onCallApp").on("click", function(){
    var callAppUrl = $("#callAppUrl").val().replace(/(\s*$)/g, "");
    var encodeCallAppUrl = "https://h5itest1.dfzq.com.cn/html5-openlibs/callApp.html?callAppUrl=" + encodeURIComponent(callAppUrl);
    console.log("[唤起App] -> 原始地址：" + callAppUrl + " 编码后地址：" + encodeCallAppUrl);
    var params = {
      title: "唤起App",
      uri: encodeCallAppUrl
    };
    console.log("[onNavigateTo params]: " + JSON.stringify(params));
    window.localStorage['callAppUrl_20220531'] = params.uri;
    fastman.onNavigateTo(params);
  });

  // 查询适老化模式是否开启
  $("#onQueryAgeAppropriateMode").on("click", function(){
    console.log("查询适老化模式是否开启");
    fastman.onQueryAgeAppropriateMode({
      success: function(res) {
        weui.alert(JSON.stringify(res), { title: "适老化模式" });
      },
      fail: function (err) {
        console.error(err.info)
      }
    });
  });

  // APP拉起微信小程序
  $("#onRedirectToWeiMini").on("click", function(){
    console.log("APP拉起微信小程序");
    var userName = $("#onRedirectToWeiMini_userName").val();
    var path = $("#onRedirectToWeiMini_path").val();
    var miniprogramType = $("input[name='miniprogramType']:checked").val();
    fastman.onRedirectToWeiMini({
      userName: userName,
      path: path,
      miniprogramType: parseInt(miniprogramType),
      success: function(res) {
        weui.alert("APP成功拉起微信小程序");
      },
      fail: function (err) {
        console.error(err.info)
      }
    });
  });

  // 隐私协议撤回
  $("#onRevokePrivacyAgreement").on("click", function(){
    console.log("调用隐私协议撤回桥接指令");
    weui.confirm('尊敬的用户，根据《中华人⺠共和国网络安全法》等相关规定，东方证券建议您同意签署《东方赢家APP隐私政策》。当您撤回同意后，东方赢家APP将会停止运行并自动退出。退出后东方赢家APP会停止收集您的个人信息，但您撤回同意的决定，不会影响此前基于您的授权而开展的个人信息处理。若您想继续使用东方赢家APP，需要您重新启动APP并同意本协议后方可正常使用。', {
      buttons: [{
          label: '取消',
          type: 'default',
          onClick: function(){ console.log('隐私协议撤回-取消操作') }
      }, {
          label: '撤回同意，退出',
          type: 'primary',
          onClick: function(){
            fastman.onRevokePrivacyAgreement({
              success: function(res) {
                weui.alert("操作成功");
              },
              fail: function (err) {
                console.error(err.info)
              }
            });
          }
      }]
    });
  });

  // PDF阅读
  $("#onPdfReader").on("click", function(){
    console.log("拉起PDF阅读");
    var pdfUrl = $("#pdfReader").val();
    fastman.onPdfReader({
      pdfUrl: pdfUrl,
      success: function(res) {
        console.log("成功拉起PDF阅读");
      },
      fail: function (err) {
        console.error(err.info)
      }
    });
  });

  // App内中台TCP通道接口调用
  $("#onMpTcpChannel").on("click", function(){
    var functionalLocator = $("#functionalLocator").val();
    var dataJsonStr = $("#dataJsonStr").val();
    var data = {};
    try {
      data = JSON.parse(dataJsonStr);
    } catch(err) {
      weui.alert("JSON格式错误，请参考示例的格式来传递", { title: "onMpTcpChannel error" });
    }
    var params = {
      functionalLocator: functionalLocator,
      data: data,
      success: function(res) {
        console.log(`[onMpTcpChannel] <- ${JSON.stringify(res)}`);
        weui.alert(JSON.stringify(res));
      },
      fail: function (err) {
        console.log(`[onMpTcpChannel] <- ${JSON.stringify(err)}`);
        weui.alert(JSON.stringify(err), { title: "onMpTcpChannel fail" });
      }
    };
    console.log(`[onMpTcpChannel] -> ${JSON.stringify(params)}`);
    fastman.onMpTcpChannel(params);
  });

  // 唤起微信APP进行微信登录
  $("#onWxLogin").on("click", function(){
    var wxLoginScope = $("#wxLoginScope").val();
    var wxLoginState = $("#wxLoginState").val();
    var params = {
      scope: wxLoginScope,
      state: wxLoginState,
      success: function(res) {
        console.log(`[onWxLogin] <- ${JSON.stringify(res)}`);
        weui.alert(JSON.stringify(res));
      },
      fail: function (err) {
        console.log(`[onWxLogin] <- ${JSON.stringify(err)}`);
        weui.alert(JSON.stringify(err), { title: "onWxLogin fail" });
      }
    };
    console.log(`[onWxLogin] -> ${JSON.stringify(params)}`);
    fastman.onWxLogin(params);
  });

  // 唤起微信APP进行微信登录
  $("#onWifiConnect").on("click", function(){
    var params = {
      success: function(res) {
        console.log(`[onWifiConnect] <- ${JSON.stringify(res)}`);
        weui.alert(JSON.stringify(res));
      },
      fail: function (err) {
        console.log(`[onWifiConnect] <- ${JSON.stringify(err)}`);
        weui.alert(JSON.stringify(err), { title: "onWifiConnect fail" });
      }
    };
    console.log(`[onWifiConnect] -> ${JSON.stringify(params)}`);
    fastman.onWifiConnect(params);
  });

}